package com.mike.annotation;

import com.mike.annotation.annotation.TestAnnotation;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.util.ClassUtils;

import java.io.IOException;
import java.lang.annotation.Target;

/**
 * Hello world!
 *
 */
public class App 
{

    public static void main( String[] args ) throws IOException {
         ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();

//        System.out.println( "Hello World!" );
        AnnotationTypeFilter annotationTypeFilter = new AnnotationTypeFilter(TestAnnotation.class,false);


        String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
                ClassUtils.convertClassNameToResourcePath("com.mike.annotation") + "/**/*.class";
//        Resource[] resources = resourcePatternResolver.getResources(pattern);
//        MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
//        for (Resource resource : resources) {
//            if (resource.isReadable()) {
//                MetadataReader reader = readerFactory.getMetadataReader(resource);
//                String className = reader.getClassMetadata().getClassName();
//                System.out.println(className+" = [" + annotationTypeFilter.match(reader,readerFactory) + "]");
//
//            }
//        }
        MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
        MetadataReader reader = metadataReaderFactory.getMetadataReader("com.mike.annotation.TestClass");
        System.out.println("args = [" + annotationTypeFilter.match(reader,metadataReaderFactory) + "]");

    }
}
